package wtws;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

import wtws.manager.in.SystemStatusMsgGenerator;
import wtws.manager.in.interf.MessageReader;
import wtws.manager.out.interf.MessageWriter;
import wtws.message.interf.TdwrProdMessage;
import wtws.util.JobConfig;
import wtws.util.PropertyManager;

public class WtwsJob {

	private MessageReader mr;
	private MessageWriter mw;
	private Queue<TdwrProdMessage> mQueue;

	public WtwsJob(MessageReader mr, MessageWriter mw) {
		mQueue = new ConcurrentLinkedQueue<TdwrProdMessage>();
		try {
			JobConfig jobConfig = PropertyManager.loadProperty(new FileInputStream("xband.properties"));
			mr.setJobConfig(jobConfig);
			mr.setQueue(mQueue);
			mw.setQueue(mQueue);
			this.mr = mr;
			this.mw = mw;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

	}

	public void runJob() {
		try {
			new Thread(new SystemStatusMsgGenerator(mQueue)).start();
			new Thread(mr).start();
			mw.start();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
